// index.js
import express from "express";
import cors from "cors";
import connectDB from "./db.js"; // 补全 .js 后缀
import path from "path";
import uploadRoutes from "./routes/upload.js";
import userRoutes from "./routes/user.js";
import chartRoutes from "./routes/chart.js";
import transferRouters from "./routes/transfer.js";

const app = express();
app.use(cors());
app.use(express.json());

app.set("enableReferer", false); // 默认
app.set("enableToken", false);

// 静态托管上传文件
app.use("/uploads", express.static(path.resolve("./uploads")));

// 注册上传路由
app.use("/api", uploadRoutes);

// 挂载其它路由
app.use("/api/user", userRoutes);
app.use("/api/chart", chartRoutes);
app.use("/api/transfer", transferRouters);

// 启动
connectDB().then(() => {
  app.listen(3000, () => {
    console.log("🚀 Server running at http://localhost:3000");
  });
});
